#include "ResizeEffect.h"

#include <stdlib.h>
#include <iostream>
#include "Poco/Exception.h"


using namespace std;
 
using Poco::Exception;
using cv::resize;
using cv::Size;
using cv::INTER_NEAREST;
using cv::INTER_LINEAR;
using cv::INTER_AREA;
using cv::INTER_CUBIC;
using cv::INTER_LANCZOS4;


ResizeEffect::ResizeEffect(string scaleFactorX, string scaleFactorY, string interpolation)
{
    // Parse scaleFactorX/Y
    this->scaleFactorX = atof(scaleFactorX.c_str());
    this->scaleFactorY = atof(scaleFactorY.c_str());
        
    // Parse interpolation
    if(interpolation=="INTER_NEAREST")
        this->interpolation = INTER_NEAREST;
    else if(interpolation=="INTER_LINEAR")
        this->interpolation = INTER_LINEAR;
    else if(interpolation=="INTER_AREA")
        this->interpolation = INTER_AREA;
    else if(interpolation=="INTER_CUBIC")
        this->interpolation = INTER_CUBIC;
    else if(interpolation=="INTER_LANCZOS4")
        this->interpolation = INTER_LANCZOS4;             
    else
        throw Exception(string("ResizeEffect unknown interpolation value: ") + interpolation);
}

Mat ResizeEffect::run(const Mat& src)
{
    cout << "Running ResizeEffect" << endl;
    Mat dst;
    resize(src, dst, Size(), this->scaleFactorX, this->scaleFactorY, this->interpolation);
    return dst;
}